/*
 * @(#)WebXmlSessionTimeOutReader.java
 *
 * Copyright 2012 by ShenY BIS, All rights reserved.
 */

package com.bis.framework.util.common;

import java.io.File;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

/**
 * WebXmlSessionTimeOutReader
 * 
 * @author BIS 2012-12-24
 */
public class WebXmlSessionTimeOutReader
{

    /**
     * SessionTimeOutReader
     * @Description:
     * @return
     */
    public static int SessionTimeOutReader()
    {
        int timeCount = 30;
        try
        {
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            String path = Thread.currentThread().getContextClassLoader().getResource("").getPath().toString();
            path = path.substring(0, path.lastIndexOf("classes"));

            DocumentBuilder builder = factory.newDocumentBuilder();
            Document document = builder.parse(new File(path + "web.xml"));
            Element rootElement = document.getDocumentElement();

            NodeList list = rootElement.getElementsByTagName("session-timeout");
            Element element = (Element) list.item(0);
            timeCount = Integer.parseInt(element.getChildNodes().item(0).getNodeValue());
        }
        catch (Exception e)
        {
            //System.out.println("exception:" + e.getMessage());
            return timeCount;
        }
        return timeCount;
    }

}
